package main

import (
	"fmt"
	"math"
	"time"
)

func reverse(x int) int {

	if x < math.MinInt32 || x > math.MaxInt32 {
		return 0
	}
	if x < 0 {
		return -reverse(-x)
	}
	result := 0

	for x > 0 {

		new := x % 10
		result = result*10 + new
		x = x / 10
		// fmt.Println(x, new, result)
	}
	if result < math.MinInt32 || result > math.MaxInt32 {
		return 0
	}

	return result

}

func main() {
	start := time.Now()
	grid := 153423646
	result := reverse(grid)
	cost := time.Since(start)
	fmt.Println("result:", result)
	fmt.Println(cost)

}
